import { CqkjMap } from './CqkjMap'

export interface MapElementOption {
  name: string
  show: boolean
}

export abstract class MapElement<T extends MapElementOption> {
  protected _cache: any = {}
  readonly map: CqkjMap
  readonly option: T

  /** 显示 */
  abstract get show(): boolean

  abstract set show(val)

  constructor(map: CqkjMap, option: T) {
    this.map = map
    this.option = option
    map.elements.get(option.name)?.distroy()
    map.elements.set(option.name, this)
  }

  distroy() {
    this.onDestroy()
    this.map.elements.delete(this.option.name)
  }

  onFrame?(): void
  onBeforeViewChange?(): void
  onViewChange?(): void
  onAfterViewChange?(): void
  onMapMounted?(): void
  onMapUnMounted?(): void
  onMouseMove?(): void
  onModeChange?(): void

  abstract onDestroy(): void
}
